<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
	<head>
	<title>收银台</title>
	<jsp:include page="header.jsp"></jsp:include>
	</head>
	<style>
		.my-button {
			display: block;
			border: none;
			width: 100%;
			height: 42px;
			line-height: 42px;
			font-size: 21px;
			color: #ffffff;
			background-color: red;
		}
		.my-button {
			display: block;
			width: 100%;
			height:100%;
			border:none;
			margin-top:0px;
			background-color:red;
			color: #ffffff;
			text-align: center;
		}
	</style>
	<body>
		<div class="weui-cells">
		  <div class="weui-cell">
		    <div class="weui-cell__bd">
		      <p>订单编号</p>
		    </div>
		    <div class="weui-cell__ft">${id}</div>
		  </div>
		</div>
		<div class="weui-cells">
		  <div class="weui-cell">
		    <div class="weui-cell__bd">
		      <p>订单价格</p>
		    </div>
		    <div class="weui-cell__ft"><span style="color: red;">￥${sum}</span></div>
		  </div>
		</div>
	<input type="hidden" name="appId" value="${appId}">
    <input type="hidden" name="nonceStr" value="${nonceStr}">
    <input type="hidden" name="prepayId" value="${prepayId}">
    <input type="hidden" name="paySign" value="${paySign}">
    <input type="hidden" name="timeStamp" value="${timeStamp}">
	<div class="weui-tabbar">
		<a href="javascritpt:;" class="my-button" id="my_button">微信支付</a>
	</div>
	<jsp:include page="foot.jsp"></jsp:include>
	<script type="text/javascript">
		$('#my_button').click(function(){
			if (typeof WeixinJSBridge == "undefined"){
	            if (document.addEventListener){
	                document.addEventListener('WeixinJSBridgeReady', onBridgeReady, false);
	            }else if (document.attachEvent){
	                document.attachEvent('WeixinJSBridgeReady', onBridgeReady);
	                document.attachEvent('onWeixinJSBridgeReady', onBridgeReady);
	            }
	        }else {
	            onBridgeReady();
	        }
		});
		function onBridgeReady(){
	        var appId = $("input[name='appId']").val();
	        var nonceStr = $("input[name='nonceStr']").val();
	        var prepayId = $("input[name='prepayId']").val();
	        var paySign = $("input[name='paySign']").val();
	        var timeStamp = $("input[name='timeStamp']").val();
	        WeixinJSBridge.invoke(
	                'getBrandWCPayRequest', {
	                    "appId":appId,
	                    "timeStamp":timeStamp,
	                    "nonceStr":nonceStr,
	                    "package":prepayId,
	                    "signType":"MD5",
	                    "paySign":paySign
	                },
	            function(res){
	                if(res.err_msg == "get_brand_wcpay_request:ok" ) {
	                    location.href="/phone/payOk";
	                }else {//这里支付失败和支付取消统一处理
	                    //mui.alert("支付取消");
	                    location.href="/phone/payError";
	                }
	            }
	        );
	    }
	</script>
	</body>
	</html>